<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/doc/src/examples/worldtimeclockbuilder.qdoc -->
<head>
  <title>Qt 4.3: World Time Clock Builder Example</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">World Time Clock Builder Example<br /><small></small></h1>
<p>Files:</p>
<ul>
<li><a href="designer-worldtimeclockbuilder-main-cpp.html">designer/worldtimeclockbuilder/main.cpp</a></li>
<li><a href="designer-worldtimeclockbuilder-worldtimeclockbuilder-qrc.html">designer/worldtimeclockbuilder/worldtimeclockbuilder.qrc</a></li>
</ul>
<p>The World Time Clock Builder example shows how forms created with Qt Designer that contain custom widgets can be dynamically generated at run-time.</p>
<p align="center"><img src="images/worldtimeclockbuilder-example.png" /></p><p>This example uses a form containing the custom widget plugin described in the <a href="designer-worldtimeclockplugin.html">World Time Clock Plugin</a> example, and dynamically generates a user interface using the <a href="quiloader.html">QUiLoader</a> class, part of the <a href="qtuitools.html">QtUiTools</a> module.</p>
<a name="preparation"></a>
<h2>Preparation</h2>
<p>As with the <a href="designer-calculatorbuilder.html">Calculator Builder</a> example, the project file for this example needs to include the appropriate definitions to ensure that it is built against the required Qt modules.</p>
<pre> CONFIG      += uitools
 SOURCES     = main.cpp
 RESOURCES   = worldtimeclockbuilder.qrc</pre>
<p>By appending <tt>form</tt> to the <tt>CONFIG</tt> declaration, we instruct <tt>qmake</tt> to generate a dependency on the <tt>libQtUiTools</tt> library containing the <a href="qtuitools.html">QtUiTools</a> classes.</p>
<p>Note that we do not inform <tt>qmake</tt> about any .ui files, and so none will be processed and built into the application. The resource file contains an entry for the particular form that we wish to use:</p>
<pre> &lt;!DOCTYPE RCC&gt;&lt;RCC version=&quot;1.0&quot;&gt;
 &lt;qresource prefix=&quot;/forms&quot;&gt;
    &lt;file&gt;form.ui&lt;/file&gt;
 &lt;/qresource&gt;
 &lt;/RCC&gt;</pre>
<p>Forms do not need to be included with the application in this way. We only include a form in the application's resources for convenience, and to keep the example short.</p>
<a name="loading-and-building-the-form"></a>
<h2>Loading and Building the Form</h2>
<p>Since this example only loads and displays a pre-prepared form, all of the work can be done in the main() function. We are using a class from the <a href="qtuitools.html">QtUiTools</a> library so, in addition to any other Qt classes that are normally required to write an application, we must include the appropriate header file:</p>
<pre> #include &lt;QtUiTools&gt;</pre>
<p>The main function initializes the resource system with the <a href="qdir.html#Q_INIT_RESOURCE">Q_INIT_RESOURCE</a>() macro and constructs an <a href="qapplication.html">QApplication</a> instance in the usual way:</p>
<pre> int main(int argc, char *argv[])
 {
     Q_INIT_RESOURCE(worldtimeclockbuilder);

     QApplication app(argc, argv);

     QUiLoader loader;</pre>
<p>We construct a <a href="quiloader.html">QUiLoader</a> object to handle the form we want to use.</p>
<p>The form itself is obtained from the resource file system using the path defined in the resource file. We use the form loader to load and construct the form:</p>
<pre>     QFile file(&quot;:/forms/form.ui&quot;);
     file.open(QFile::ReadOnly);

     QWidget *widget = loader.load(&amp;file);

     file.close();
     widget-&gt;show();</pre>
<p>Once the form has been loaded, the resource file can be closed and the widget is shown.</p>
<pre>     return app.exec();
 }</pre>
<p>The form loader ensures that all the signal and slot connections between objects in the form are set up correctly when the form is loaded. As a result, the time is updated by the World Time Clock widget, and the time zone spin box can be used to change the position of the hour hand.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
